package demo.practice.tree.segment;

public class P1893 {

    public boolean isCovered(int[][] ranges, int left, int right) {
        if (ranges == null || ranges.length == 0) {
            return false;
        }

        int min = Integer.MAX_VALUE;
        int max = Integer.MIN_VALUE;

        for (int[] range : ranges) {

            min = Math.min(min, range[0]);
            max = Math.max(max, range[1]);
        }


        SegmentTreeOperator tree = new SegmentTreeOperator(max+1, 0, Integer::sum);
        for (int[] range : ranges) {
           for(int i=range[0];i<=range[1];i++){
               tree.update(i,1);
           }
        }

        return tree.query(left,right)== right-left+1;
    }


}
